<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE html 
     PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
     "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
  <title>Class: Globalize::Currency</title>
  <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
  <meta http-equiv="Content-Script-Type" content="text/javascript" />
  <link rel="stylesheet" href="../.././rdoc-style.css" type="text/css" media="screen" />
  <script type="text/javascript">
  // <![CDATA[

  function popupCode( url ) {
    window.open(url, "Code", "resizable=yes,scrollbars=yes,toolbar=no,status=no,height=150,width=400")
  }

  function toggleCode( id ) {
    if ( document.getElementById )
      elem = document.getElementById( id );
    else if ( document.all )
      elem = eval( "document.all." + id );
    else
      return false;

    elemStyle = elem.style;
    
    if ( elemStyle.display != "block" ) {
      elemStyle.display = "block"
    } else {
      elemStyle.display = "none"
    }

    return true;
  }
  
  // Make codeblocks hidden by default
  document.writeln( "<style type=\"text/css\">div.method-source-code { display: none }</style>" )
  
  // ]]>
  </script>

</head>
<body>



    <div id="classHeader">
        <table class="header-table">
        <tr class="top-aligned-row">
          <td><strong>Class</strong></td>
          <td class="class-name-in-header">Globalize::Currency</td>
        </tr>
        <tr class="top-aligned-row">
            <td><strong>In:</strong></td>
            <td>
                <a href="../../files/vendor/plugins/globalize/lib/globalize/models/currency_rb.html">
                vendor/plugins/globalize/lib/globalize/models/currency.rb
                </a>
        <br />
            </td>
        </tr>

        <tr class="top-aligned-row">
            <td><strong>Parent:</strong></td>
            <td>
                Object
            </td>
        </tr>
        </table>
    </div>
  <!-- banner header -->

  <div id="bodyContent">



  <div id="contextContent">

    <div id="description">
      <p>
This is what you use for representing money in your ActiveRecord models. It
stores values as integers internally and in the database, to safeguard
precision and rounding.
</p>
<p>
More importantly for globalization freaks, it prints out the <a
href="Currency.html#M000058">amount</a> correctly in the current locale,
via the handy <a href="Currency.html#M000057">format</a> method. Try it!
</p>
<p>
Example:
</p>
<pre>
  class Product &lt; ActiveRecord::Base
    composed_of :price, :class_name =&gt; &quot;Globalize::Currency&quot;,
      :mapping =&gt; [ %w(price cents) ]
  end

  product.price -&gt; &quot;SFr. 483'232.43&quot;
</pre>

    </div>


   </div>

    <div id="method-list">
      <h3 class="section-bar">Methods</h3>

      <div class="name-list">
      <a href="#M000055">*</a>&nbsp;&nbsp;
      <a href="#M000053">+</a>&nbsp;&nbsp;
      <a href="#M000054">-</a>&nbsp;&nbsp;
      <a href="#M000056">/</a>&nbsp;&nbsp;
      <a href="#M000052">&lt;=&gt;</a>&nbsp;&nbsp;
      <a href="#M000058">amount</a>&nbsp;&nbsp;
      <a href="#M000062">empty?</a>&nbsp;&nbsp;
      <a href="#M000057">format</a>&nbsp;&nbsp;
      <a href="#M000050">free</a>&nbsp;&nbsp;
      <a href="#M000051">na</a>&nbsp;&nbsp;
      <a href="#M000063">na?</a>&nbsp;&nbsp;
      <a href="#M000047">new</a>&nbsp;&nbsp;
      <a href="#M000048">no_cents</a>&nbsp;&nbsp;
      <a href="#M000049">no_cents=</a>&nbsp;&nbsp;
      <a href="#M000060">parse</a>&nbsp;&nbsp;
      <a href="#M000061">to_currency</a>&nbsp;&nbsp;
      <a href="#M000059">to_s</a>&nbsp;&nbsp;
      </div>
    </div>

  </div>


    <!-- if includes -->
    <div id="includes">
      <h3 class="section-bar">Included Modules</h3>

      <div id="includes-list">
        <span class="include-name">Comparable</span>
      </div>
    </div>

    <div id="section">





    <div id="attribute-list">
      <h3 class="section-bar">Attributes</h3>

      <div class="name-list">
        <table>
        <tr class="top-aligned-row context-row">
          <td class="context-item-name">cents</td>
          <td class="context-item-value">&nbsp;[R]&nbsp;</td>
          <td class="context-item-desc"></td>
        </tr>
        </table>
      </div>
    </div>
      


    <!-- if method_list -->
    <div id="methods">
      <h3 class="section-bar">Public Class methods</h3>

      <div id="method-M000050" class="method-detail">
        <a name="M000050"></a>

        <div class="method-heading">
          <a href="#M000050" class="method-signature">
          <span class="method-name">free</span><span class="method-args">()</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Returns the <a href="Currency.html">Currency</a> object representing a
price of 0.
</p>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000050-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000050-source">
<pre>
    <span class="ruby-comment cmt"># File vendor/plugins/globalize/lib/globalize/models/currency.rb, line 42</span>
42:     <span class="ruby-keyword kw">def</span> <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">free</span>
43:       <span class="ruby-ivar">@@free</span>
44:     <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M000051" class="method-detail">
        <a name="M000051"></a>

        <div class="method-heading">
          <a href="#M000051" class="method-signature">
          <span class="method-name">na</span><span class="method-args">()</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Returns the <a href="Currency.html">Currency</a> object representing an
unknown price.
</p>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000051-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000051-source">
<pre>
    <span class="ruby-comment cmt"># File vendor/plugins/globalize/lib/globalize/models/currency.rb, line 50</span>
50:     <span class="ruby-keyword kw">def</span> <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">na</span>
51:       <span class="ruby-ivar">@@na</span>
52:     <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M000047" class="method-detail">
        <a name="M000047"></a>

        <div class="method-heading">
          <a href="#M000047" class="method-signature">
          <span class="method-name">new</span><span class="method-args">(cents)</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Creates a <a href="Currency.html#M000047">new</a> <a
href="Currency.html">Currency</a> object, given cents. This is used to tie
into the ActiveRecord aggregation stuff.
</p>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000047-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000047-source">
<pre>
    <span class="ruby-comment cmt"># File vendor/plugins/globalize/lib/globalize/models/currency.rb, line 30</span>
30:     <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">initialize</span>(<span class="ruby-identifier">cents</span>)
31:       <span class="ruby-ivar">@cents</span> = <span class="ruby-identifier">cents</span>.<span class="ruby-identifier">nil?</span> <span class="ruby-value">? </span><span class="ruby-keyword kw">nil</span> <span class="ruby-operator">:</span> <span class="ruby-identifier">cents</span>.<span class="ruby-identifier">to_i</span>
32:     <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M000048" class="method-detail">
        <a name="M000048"></a>

        <div class="method-heading">
          <a href="#M000048" class="method-signature">
          <span class="method-name">no_cents</span><span class="method-args">()</span>
          </a>
        </div>
      
        <div class="method-description">
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000048-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000048-source">
<pre>
    <span class="ruby-comment cmt"># File vendor/plugins/globalize/lib/globalize/models/currency.rb, line 35</span>
35:     <span class="ruby-keyword kw">def</span> <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">no_cents</span>; <span class="ruby-ivar">@@no_cents</span> <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M000049" class="method-detail">
        <a name="M000049"></a>

        <div class="method-heading">
          <a href="#M000049" class="method-signature">
          <span class="method-name">no_cents=</span><span class="method-args">(val)</span>
          </a>
        </div>
      
        <div class="method-description">
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000049-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000049-source">
<pre>
    <span class="ruby-comment cmt"># File vendor/plugins/globalize/lib/globalize/models/currency.rb, line 36</span>
36:     <span class="ruby-keyword kw">def</span> <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">no_cents=</span>(<span class="ruby-identifier">val</span>); <span class="ruby-ivar">@@no_cents</span> = <span class="ruby-identifier">val</span> <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M000060" class="method-detail">
        <a name="M000060"></a>

        <div class="method-heading">
          <a href="#M000060" class="method-signature">
          <span class="method-name">parse</span><span class="method-args">(num)</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Parse a string or number into a currency object. Easier to use than <a
href="Currency.html#M000047">new</a>.
</p>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000060-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000060-source">
<pre>
     <span class="ruby-comment cmt"># File vendor/plugins/globalize/lib/globalize/models/currency.rb, line 147</span>
147:     <span class="ruby-keyword kw">def</span> <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">parse</span>(<span class="ruby-identifier">num</span>)
148:       <span class="ruby-keyword kw">case</span>
149:       <span class="ruby-keyword kw">when</span> <span class="ruby-identifier">num</span>.<span class="ruby-identifier">is_a?</span>(<span class="ruby-constant">String</span>)
150:         <span class="ruby-identifier">raise</span> <span class="ruby-constant">ArgumentError</span>, <span class="ruby-node">&quot;Not an amount (#{num})&quot;</span> <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">num</span>.<span class="ruby-identifier">delete</span>(<span class="ruby-value str">&quot;^0-9&quot;</span>).<span class="ruby-identifier">empty?</span>
151:         <span class="ruby-identifier">_dollars</span>, <span class="ruby-identifier">_cents</span> = <span class="ruby-identifier">num</span>.<span class="ruby-identifier">delete</span>(<span class="ruby-value str">&quot;^0-9.&quot;</span>).<span class="ruby-identifier">split</span>(<span class="ruby-value str">'.'</span>, <span class="ruby-value">2</span>)
152:         <span class="ruby-identifier">_cents</span> = <span class="ruby-identifier">_cents</span> <span class="ruby-value">? </span><span class="ruby-identifier">_cents</span>[<span class="ruby-value">0</span>,<span class="ruby-value">2</span>] <span class="ruby-operator">:</span> <span class="ruby-value">0</span>
153:         <span class="ruby-constant">Currency</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">_dollars</span>.<span class="ruby-identifier">to_i</span> <span class="ruby-operator">*</span> <span class="ruby-value">100</span> <span class="ruby-operator">+</span> <span class="ruby-identifier">_cents</span>.<span class="ruby-identifier">to_i</span>)
154:       <span class="ruby-keyword kw">when</span> <span class="ruby-identifier">num</span>.<span class="ruby-identifier">is_a?</span>(<span class="ruby-constant">Numeric</span>)
155:         <span class="ruby-constant">Currency</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">num</span> <span class="ruby-operator">*</span> <span class="ruby-value">100</span>)
156:       <span class="ruby-keyword kw">when</span> <span class="ruby-identifier">num</span>.<span class="ruby-identifier">is_a?</span>(<span class="ruby-constant">NilClass</span>)
157:         <span class="ruby-constant">Currency</span>.<span class="ruby-identifier">na</span>
158:       <span class="ruby-keyword kw">else</span>
159:         <span class="ruby-identifier">raise</span> <span class="ruby-constant">ArgumentError</span>, <span class="ruby-node">&quot;Unrecognized object #{num.class.name} for Currency&quot;</span>
160:       <span class="ruby-keyword kw">end</span>
161:     <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <h3 class="section-bar">Public Instance methods</h3>

      <div id="method-M000055" class="method-detail">
        <a name="M000055"></a>

        <div class="method-heading">
          <a href="#M000055" class="method-signature">
          <span class="method-name">*</span><span class="method-args">(amount)</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Multiply money by <a href="Currency.html#M000058">amount</a>
</p>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000055-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000055-source">
<pre>
    <span class="ruby-comment cmt"># File vendor/plugins/globalize/lib/globalize/models/currency.rb, line 83</span>
83:     <span class="ruby-keyword kw">def</span> <span class="ruby-operator">*</span>(<span class="ruby-identifier">amount</span>)
84:       <span class="ruby-keyword kw">return</span> <span class="ruby-constant">Currency</span>.<span class="ruby-identifier">new</span>(<span class="ruby-keyword kw">nil</span>) <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">na?</span>
85:       <span class="ruby-identifier">new_cents</span> = <span class="ruby-identifier">amount</span> <span class="ruby-operator">*</span> <span class="ruby-identifier">cents</span>;
86:       <span class="ruby-identifier">new_cents</span> = <span class="ruby-identifier">new_cents</span>.<span class="ruby-identifier">round</span> <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">new_cents</span>.<span class="ruby-identifier">respond_to?</span> <span class="ruby-identifier">:round</span>
87:       <span class="ruby-constant">Currency</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">new_cents</span>)
88:     <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M000053" class="method-detail">
        <a name="M000053"></a>

        <div class="method-heading">
          <a href="#M000053" class="method-signature">
          <span class="method-name">+</span><span class="method-args">(other_money)</span>
          </a>
        </div>
      
        <div class="method-description">
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000053-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000053-source">
<pre>
    <span class="ruby-comment cmt"># File vendor/plugins/globalize/lib/globalize/models/currency.rb, line 68</span>
68:     <span class="ruby-keyword kw">def</span> <span class="ruby-operator">+</span>(<span class="ruby-identifier">other_money</span>)
69:       <span class="ruby-identifier">raise</span> <span class="ruby-constant">TypeError</span>, <span class="ruby-value str">&quot;parameter to Currency#+ must be Currency object&quot;</span> <span class="ruby-keyword kw">unless</span>
70:         <span class="ruby-identifier">other_money</span>.<span class="ruby-identifier">kind_of?</span> <span class="ruby-constant">Currency</span>
71:       (<span class="ruby-identifier">na?</span> <span class="ruby-operator">||</span> <span class="ruby-identifier">other_money</span>.<span class="ruby-identifier">na?</span>) <span class="ruby-operator">?</span> <span class="ruby-constant">Currency</span>.<span class="ruby-identifier">na</span> <span class="ruby-operator">:</span>
72:         <span class="ruby-constant">Currency</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">cents</span> <span class="ruby-operator">+</span> <span class="ruby-identifier">other_money</span>.<span class="ruby-identifier">cents</span>)
73:     <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M000054" class="method-detail">
        <a name="M000054"></a>

        <div class="method-heading">
          <a href="#M000054" class="method-signature">
          <span class="method-name">-</span><span class="method-args">(other_money)</span>
          </a>
        </div>
      
        <div class="method-description">
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000054-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000054-source">
<pre>
    <span class="ruby-comment cmt"># File vendor/plugins/globalize/lib/globalize/models/currency.rb, line 75</span>
75:     <span class="ruby-keyword kw">def</span> <span class="ruby-operator">-</span>(<span class="ruby-identifier">other_money</span>)
76:       <span class="ruby-identifier">raise</span> <span class="ruby-constant">TypeError</span>, <span class="ruby-value str">&quot;parameter to Currency#+ must be Currency object&quot;</span> <span class="ruby-keyword kw">unless</span>
77:         <span class="ruby-identifier">other_money</span>.<span class="ruby-identifier">kind_of?</span> <span class="ruby-constant">Currency</span>
78:       (<span class="ruby-identifier">na?</span> <span class="ruby-operator">||</span> <span class="ruby-identifier">other_money</span>.<span class="ruby-identifier">na?</span>) <span class="ruby-operator">?</span> <span class="ruby-constant">Currency</span>.<span class="ruby-identifier">na</span> <span class="ruby-operator">:</span>
79:         <span class="ruby-constant">Currency</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">cents</span> <span class="ruby-operator">-</span> <span class="ruby-identifier">other_money</span>.<span class="ruby-identifier">cents</span>)
80:     <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M000056" class="method-detail">
        <a name="M000056"></a>

        <div class="method-heading">
          <a href="#M000056" class="method-signature">
          <span class="method-name">/</span><span class="method-args">(amount)</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Divide money by <a href="Currency.html#M000058">amount</a>
</p>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000056-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000056-source">
<pre>
    <span class="ruby-comment cmt"># File vendor/plugins/globalize/lib/globalize/models/currency.rb, line 91</span>
91:     <span class="ruby-keyword kw">def</span> <span class="ruby-operator">/</span>(<span class="ruby-identifier">amount</span>)
92:       <span class="ruby-keyword kw">return</span> <span class="ruby-constant">Currency</span>.<span class="ruby-identifier">new</span>(<span class="ruby-keyword kw">nil</span>) <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">na?</span>
93:       <span class="ruby-identifier">new_cents</span> = <span class="ruby-identifier">cents</span> <span class="ruby-operator">/</span> <span class="ruby-identifier">amount</span>;
94:       <span class="ruby-identifier">new_cents</span> = <span class="ruby-identifier">new_cents</span>.<span class="ruby-identifier">round</span> <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">new_cents</span>.<span class="ruby-identifier">respond_to?</span> <span class="ruby-identifier">:round</span>
95:       <span class="ruby-constant">Currency</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">new_cents</span>)
96:     <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M000052" class="method-detail">
        <a name="M000052"></a>

        <div class="method-heading">
          <a href="#M000052" class="method-signature">
          <span class="method-name">&lt;=&gt;</span><span class="method-args">(other)</span>
          </a>
        </div>
      
        <div class="method-description">
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000052-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000052-source">
<pre>
    <span class="ruby-comment cmt"># File vendor/plugins/globalize/lib/globalize/models/currency.rb, line 54</span>
54:     <span class="ruby-keyword kw">def</span> <span class="ruby-operator">&lt;=&gt;</span>(<span class="ruby-identifier">other</span>)
55:       <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">other</span>.<span class="ruby-identifier">respond_to?</span> <span class="ruby-identifier">:cents</span>
56:         <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">na?</span>
57:           <span class="ruby-identifier">other</span>.<span class="ruby-identifier">na?</span> <span class="ruby-value">? </span><span class="ruby-value">0</span> <span class="ruby-operator">:</span> <span class="ruby-value">1</span>
58:         <span class="ruby-keyword kw">else</span>
59:           <span class="ruby-identifier">other</span>.<span class="ruby-identifier">na?</span> <span class="ruby-value">? </span><span class="ruby-operator">-</span><span class="ruby-value">1</span> <span class="ruby-operator">:</span> <span class="ruby-identifier">cents</span> <span class="ruby-operator">&lt;=&gt;</span> <span class="ruby-identifier">other</span>.<span class="ruby-identifier">cents</span>
60:         <span class="ruby-keyword kw">end</span>
61:       <span class="ruby-keyword kw">elsif</span> <span class="ruby-identifier">other</span>.<span class="ruby-identifier">kind_of?</span> <span class="ruby-constant">Integer</span>
62:         <span class="ruby-identifier">na?</span> <span class="ruby-value">? </span><span class="ruby-value">1</span> <span class="ruby-operator">:</span> <span class="ruby-identifier">cents</span> <span class="ruby-operator">&lt;=&gt;</span> <span class="ruby-identifier">other</span>
63:       <span class="ruby-keyword kw">else</span>
64:         <span class="ruby-identifier">raise</span> <span class="ruby-value str">&quot;can only compare with money or integer&quot;</span>
65:       <span class="ruby-keyword kw">end</span>      
66:     <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M000058" class="method-detail">
        <a name="M000058"></a>

        <div class="method-heading">
          <a href="#M000058" class="method-signature">
          <span class="method-name">amount</span><span class="method-args">(unlocalized = false, force_cents = false)</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Returns the formatted version of the <a
href="Currency.html#M000058">amount</a>, but without the currency symbol.
If <tt>unlocalized</tt> is true, do not <a
href="Currency.html#M000057">format</a> the number according to the current
locale, so <tt><a href="Currency.html#M000047">Currency.new(1234567)</a>
-&gt; 12345.67</tt>. This is useful for sending the <a
href="Currency.html#M000058">amount</a> to payment gateways.
</p>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000058-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000058-source">
<pre>
     <span class="ruby-comment cmt"># File vendor/plugins/globalize/lib/globalize/models/currency.rb, line 127</span>
127:     <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">amount</span>(<span class="ruby-identifier">unlocalized</span> = <span class="ruby-keyword kw">false</span>, <span class="ruby-identifier">force_cents</span> = <span class="ruby-keyword kw">false</span>)
128:       <span class="ruby-keyword kw">return</span> <span class="ruby-keyword kw">nil</span> <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">na?</span>
129:       <span class="ruby-identifier">decimal_sep</span> = <span class="ruby-identifier">unlocalized</span> <span class="ruby-value">?</span>
130:         <span class="ruby-value str">'.'</span> <span class="ruby-operator">:</span>
131:         (<span class="ruby-constant">Locale</span>.<span class="ruby-identifier">active?</span> <span class="ruby-value">? </span>
132:           (<span class="ruby-constant">Locale</span>.<span class="ruby-identifier">active</span>.<span class="ruby-identifier">currency_decimal_sep</span> <span class="ruby-operator">||</span> <span class="ruby-constant">Locale</span>.<span class="ruby-identifier">active</span>.<span class="ruby-identifier">decimal_sep</span> <span class="ruby-operator">||</span> <span class="ruby-value str">'.'</span>) <span class="ruby-operator">:</span>
133:           <span class="ruby-value str">'.'</span>)
134:       <span class="ruby-identifier">dollar_str</span> = <span class="ruby-identifier">unlocalized</span> <span class="ruby-value">? </span><span class="ruby-identifier">dollar_part</span>.<span class="ruby-identifier">to_s</span> <span class="ruby-operator">:</span> <span class="ruby-identifier">dollar_part</span>.<span class="ruby-identifier">localize</span>
135:       <span class="ruby-identifier">result</span> = <span class="ruby-identifier">dollar_str</span>
136:       <span class="ruby-identifier">result</span> <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-identifier">decimal_sep</span> <span class="ruby-operator">+</span> <span class="ruby-identifier">sprintf</span>(<span class="ruby-value str">&quot;%02d&quot;</span>, <span class="ruby-identifier">cent_part</span>) <span class="ruby-keyword kw">unless</span> 
137:         <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">class</span>.<span class="ruby-identifier">no_cents</span> <span class="ruby-operator">&amp;&amp;</span> <span class="ruby-operator">!</span><span class="ruby-identifier">force_cents</span>
138:       <span class="ruby-keyword kw">return</span> <span class="ruby-identifier">result</span>
139:     <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M000062" class="method-detail">
        <a name="M000062"></a>

        <div class="method-heading">
          <a href="#M000062" class="method-signature">
          <span class="method-name">empty?</span><span class="method-args">()</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Is the value 0? Is it free?
</p>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000062-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000062-source">
<pre>
     <span class="ruby-comment cmt"># File vendor/plugins/globalize/lib/globalize/models/currency.rb, line 169</span>
169:     <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">empty?</span>
170:       <span class="ruby-identifier">cents</span> <span class="ruby-operator">==</span> <span class="ruby-value">0</span>
171:     <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M000057" class="method-detail">
        <a name="M000057"></a>

        <div class="method-heading">
          <a href="#M000057" class="method-signature">
          <span class="method-name">format</span><span class="method-args">(options = {})</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Returns the formatted version of the <a
href="Currency.html#M000058">amount</a> in local currency. If <tt>:code
=&gt; true</tt> is specified, <a href="Currency.html#M000057">format</a>
using international 3-letter currency code. If <tt>:country</tt> is
specified as well, use that country&#8216;s currency code for formatting.
</p>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000057-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000057-source">
<pre>
     <span class="ruby-comment cmt"># File vendor/plugins/globalize/lib/globalize/models/currency.rb, line 102</span>
102:     <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">format</span>(<span class="ruby-identifier">options</span> = {})
103:       <span class="ruby-keyword kw">return</span> <span class="ruby-identifier">:no_price_available</span>.<span class="ruby-identifier">t</span>(<span class="ruby-value str">&quot;call for price&quot;</span>) <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">na?</span>
104: 
105:       <span class="ruby-identifier">force_cents</span> = <span class="ruby-identifier">options</span>[<span class="ruby-identifier">:force_cents</span>]
106:                         <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">options</span>[<span class="ruby-identifier">:code</span>]
107:         <span class="ruby-identifier">currency_code</span> = <span class="ruby-identifier">options</span>[<span class="ruby-identifier">:country</span>] <span class="ruby-operator">?</span> 
108:           <span class="ruby-identifier">options</span>[<span class="ruby-identifier">:country</span>].<span class="ruby-identifier">currency_code</span> <span class="ruby-operator">:</span> 
109:           ( <span class="ruby-constant">Locale</span>.<span class="ruby-identifier">active?</span> <span class="ruby-value">? </span><span class="ruby-constant">Locale</span>.<span class="ruby-identifier">active</span>.<span class="ruby-identifier">currency_code</span> <span class="ruby-operator">:</span> <span class="ruby-keyword kw">nil</span> )
110:         <span class="ruby-identifier">currency_code</span> <span class="ruby-value">? </span>
111:                                         <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">amount</span>(<span class="ruby-keyword kw">false</span>, <span class="ruby-identifier">force_cents</span>) <span class="ruby-operator">+</span> <span class="ruby-value str">&quot; &quot;</span> <span class="ruby-operator">+</span> <span class="ruby-identifier">currency_code</span> <span class="ruby-operator">:</span> 
112:                                         <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">amount</span>(<span class="ruby-keyword kw">false</span>, <span class="ruby-identifier">force_cents</span>)
113:       <span class="ruby-keyword kw">else</span>
114:         <span class="ruby-keyword kw">if</span> <span class="ruby-constant">Locale</span>.<span class="ruby-identifier">active?</span>
115:           <span class="ruby-identifier">fmt</span> = <span class="ruby-constant">Locale</span>.<span class="ruby-identifier">active</span>.<span class="ruby-identifier">currency_format</span> <span class="ruby-operator">||</span> <span class="ruby-value str">'$%n'</span>
116:           <span class="ruby-identifier">fmt</span>.<span class="ruby-identifier">sub</span>(<span class="ruby-value str">'%n'</span>, <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">amount</span>(<span class="ruby-keyword kw">false</span>, <span class="ruby-identifier">force_cents</span>))
117:         <span class="ruby-keyword kw">else</span>
118:           <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">amount</span> <span class="ruby-keyword kw">false</span>, <span class="ruby-identifier">force_cents</span>
119:         <span class="ruby-keyword kw">end</span>
120:       <span class="ruby-keyword kw">end</span>
121:     <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M000063" class="method-detail">
        <a name="M000063"></a>

        <div class="method-heading">
          <a href="#M000063" class="method-signature">
          <span class="method-name">na?</span><span class="method-args">()</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Is the value unknown?
</p>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000063-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000063-source">
<pre>
     <span class="ruby-comment cmt"># File vendor/plugins/globalize/lib/globalize/models/currency.rb, line 174</span>
174:     <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">na?</span>
175:       <span class="ruby-identifier">cents</span>.<span class="ruby-identifier">nil?</span>
176:     <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M000061" class="method-detail">
        <a name="M000061"></a>

        <div class="method-heading">
          <a href="#M000061" class="method-signature">
          <span class="method-name">to_currency</span><span class="method-args">()</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Conversion to self
</p>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000061-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000061-source">
<pre>
     <span class="ruby-comment cmt"># File vendor/plugins/globalize/lib/globalize/models/currency.rb, line 164</span>
164:     <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">to_currency</span>
165:       <span class="ruby-keyword kw">self</span>
166:     <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M000059" class="method-detail">
        <a name="M000059"></a>

        <div class="method-heading">
          <a href="#M000059" class="method-signature">
          <span class="method-name">to_s</span><span class="method-args">()</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Same as <a href="Currency.html#M000057">format</a> with no arguments.
</p>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000059-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000059-source">
<pre>
     <span class="ruby-comment cmt"># File vendor/plugins/globalize/lib/globalize/models/currency.rb, line 142</span>
142:     <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">to_s</span>
143:       <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">format</span>
144:     <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>


    </div>


  </div>


<div id="validator-badges">
  <p><small><a href="http://validator.w3.org/check/referer">[Validate]</a></small></p>
</div>

</body>
</html>